import ObjectManager.ObjectGame;
import javax.microedition.lcdui.game.*;

public class Terrain {
    TiledLayer tiledBackground;
    int currentX = 0, currentY = 0;
    int width = 0, height = 0;
    ObjectGame[] arrObjectGame;
    
    public Terrain(TiledLayer tiledBackground, ObjectGame[] arrObjectGame) {
       this.tiledBackground = tiledBackground;
       this.width = tiledBackground.getColumns() * tiledBackground.getCellWidth();
       this.height = tiledBackground.getRows() * tiledBackground.getCellHeight();
       this.arrObjectGame = arrObjectGame;
    }    
    
    public void Move(int dx, int dy){
        this.currentX += dx;
        this.currentY += dy;
        tiledBackground.move(dx, dy);
        for(int i = 0; i < arrObjectGame.length; i++){
            arrObjectGame[i].SetCurrentPos(arrObjectGame[i].currentX + dx, arrObjectGame[i].currentY + dy);
        }
    }
    
    public void SetCurPos(int x, int y){
        int dx = this.currentX - x;
        int dy = this.currentY - y;
        this.currentX = x;
        this.currentY = y;
        tiledBackground.setPosition(x, y);
        for(int i = 0; i < arrObjectGame.length; i++){
            arrObjectGame[i].SetCurrentPos(arrObjectGame[i].currentX - dx, arrObjectGame[i].currentY - dy);
        }
    }
}
